import json

from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
from rest_framework.response import Response


class ErrorMiddleware(MiddlewareMixin):
    def process_exception(self, request, exception):
        return HttpResponse(content=json.dumps({'msg': str(exception)}).encode('utf-8'),
                            content_type='application/json;charset=utf-8')